package cn.com.youjile.utils;

import cn.com.youjile.protobuf.ResultInfo;
import lombok.Data;

/**
 * @Author youjile
 * @CreateDate 2021/3/12
 * @Describe 返回的消息体，参考http浏览器返回的消息号进行设计
 */
@Data
public class ResultUtil {

    public static byte[] success() {
        ResultInfo.ResultMsg.Builder builder = ResultInfo.ResultMsg.newBuilder();
        builder.setCode(MsgNumUtil.success);
        builder.setMsg("操作成功");
        return builder.build().toByteArray();
    }

    public static byte[] success(String msg) {
        ResultInfo.ResultMsg.Builder builder = ResultInfo.ResultMsg.newBuilder();
        builder.setCode(MsgNumUtil.success);
        builder.setMsg(msg);
        return builder.build().toByteArray();
    }

    public static byte[] error(){
        ResultInfo.ResultMsg.Builder builder = ResultInfo.ResultMsg.newBuilder();
        builder.setCode(MsgNumUtil.error);
        builder.setMsg("操作失败");
        return builder.build().toByteArray();
    }

    public static byte[] error(String msg){
        ResultInfo.ResultMsg.Builder builder = ResultInfo.ResultMsg.newBuilder();
        builder.setCode(MsgNumUtil.error);
        builder.setMsg(msg);
        return builder.build().toByteArray();
    }


}
